package com.zc.trendsDispatch.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zc.trendsDispatch.domain.ChargeEngineRule;
import com.zc.trendsDispatch.service.IChargeEngineRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 规则策略Controller
 * 
 * @author glb
 * @date 2024-03-11
 */
@RestController
@RequestMapping("/trendsDispatch/rule")
public class ChargeEngineRuleController extends BaseController
{
    @Autowired
    private IChargeEngineRuleService chargeEngineRuleService;

    /**
     * 查询规则策略列表
     */
    @PreAuthorize("@ss.hasPermi('trendsDispatch:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChargeEngineRule chargeEngineRule)
    {
        startPage();
        List<ChargeEngineRule> list = chargeEngineRuleService.selectChargeEngineRuleList(chargeEngineRule);
        return getDataTable(list);
    }

    /**
     * 导出规则策略列表
     */
    @PreAuthorize("@ss.hasPermi('trendsDispatch:rule:export')")
    @Log(title = "规则策略", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChargeEngineRule chargeEngineRule)
    {
        List<ChargeEngineRule> list = chargeEngineRuleService.selectChargeEngineRuleList(chargeEngineRule);
        ExcelUtil<ChargeEngineRule> util = new ExcelUtil<>(ChargeEngineRule.class);
        util.exportExcel(response, list, "规则策略数据");
    }

    /**
     * 获取规则策略详细信息
     */
    @PreAuthorize("@ss.hasPermi('trendsDispatch:rule:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return AjaxResult.success(chargeEngineRuleService.selectChargeEngineRuleByRuleId(ruleId));
    }

    /**
     * 新增规则策略
     */
    @PreAuthorize("@ss.hasPermi('trendsDispatch:rule:add')")
    @Log(title = "规则策略", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChargeEngineRule chargeEngineRule)
    {
        return toAjax(chargeEngineRuleService.insertChargeEngineRule(chargeEngineRule));
    }

    /**
     * 修改规则策略
     */
    @PreAuthorize("@ss.hasPermi('trendsDispatch:rule:edit')")
    @Log(title = "规则策略", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChargeEngineRule chargeEngineRule)
    {
        return toAjax(chargeEngineRuleService.updateChargeEngineRule(chargeEngineRule));
    }

    /**
     * 删除规则策略
     */
    @PreAuthorize("@ss.hasPermi('trendsDispatch:rule:remove')")
    @Log(title = "规则策略", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(chargeEngineRuleService.deleteChargeEngineRuleByRuleIds(ruleIds));
    }
}
